<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>_入库登记(新)</title>
	<script type="text/javascript">
		var filterParam = {};
		var datatable_content;
		 $(function() {
			    $("#queryForm").validate(); 
			    $("#inputForm").validate();
				$("#_fromDate").datepicker({ format : 'yyyy-mm-dd'});
				$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
				
				var now = new Date();
				var tomorrow = new Date();
				tomorrow.setDate(now.getDate()+1);
				$("#_fromDate").val(now.Format("yyyy-MM-dd"));
				$("#_toDate").val(tomorrow.Format("yyyy-MM-dd"));
				initTable();
	       });
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/v2_instorageBillNew/queryInstorageBill',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "sScrollX":"100%",
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	{"mData": null},
	             	 {"mData": "customer.customerName"},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": "boxNum"},
	             	 {"mData": "skuNum"},
	             	 {"mData": "goodsNum"},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [2],
		              "mRender": function (data, display, row) {
							return  row.billType == "customer" ? "<font color=red>采购入库</font>" : 
									row.billType == "allot" ? "<font color=green>调拨入库</font>" :
									row.billType == "cancelOrder" ? "<font color=blue>取消单入库</font>" :
									row.billType == "returnOrder" ? "<font color=black>退回件入库</font>" :
									row.billType == "preOrder" ? "<font color=black>预约入库</font>" : "";
			           }
		            },
	             	{"aTargets": [3],
		              "mRender": function (data, display, row) {
							return  row.errorFlag == "error" ? "<font color=red>报损件</font>" : "完好件";
			           }
		            },
	             	{"aTargets": [4],
		              "mRender": function (data, display, row) {
							return  row.inwarehouse ? row.inwarehouse.groupName : "";
			           }
		            },
	             	{"aTargets": [5],
		              "mRender": function (data, display, row) {
							return  row.outwarehouse ? row.outwarehouse.groupName : "";
			           }
		            },
	             	{"aTargets": [6],
		              "mRender": function (data, display, row) {
							return  "<a href=\"${ctx}/v2_instorageBillNew/v2_toInstorageBillDetailPage/"+row.billCode+"\" title=\"【入库信息详情】\">"+row.billCode+"</a>";
			           }
		            },
	             	{"aTargets": [7],
		              "mRender": function (data, display, row) {
		            	  return  row.preBill ? row.preBill.customerOrderNo : "";
						}
		            },
	             	{"aTargets": [8],
		              "mRender": function (data, display, row) {
							
							return  row.billType == "customer" ? row.aboutCode : 
								row.billType == "allot" ? "<a href=\"${ctx}/outstorageBill/v2_toOutstorageBillDetailPage/"+row.aboutCode+"\" title=\"【调拨出库信息】\">"+row.aboutCode+"</a>" :
								row.billType == "cancelOrder" ? row.aboutCode :
								(row.billType == "returnOrder" && row.preBill) ? "<a href=\"${ctx}/v2/preInstorageBill/queryPreInstorageInfo/"+row.preBill.id+"\" title=\"【入库预约信息】\">"+row.aboutCode+"</a>" :
								(row.billType == "preOrder" && row.preBill) ? "<a href=\"${ctx}/v2/preInstorageBill/queryPreInstorageInfo/"+row.preBill.id+"\" title=\"【入库预约信息】\">"+row.aboutCode+"</a>" : row.aboutCode;
		           
			           }
		            },
	             	{"aTargets": [9],
		              "mRender": function (data, display, row) {
							return  row.preBill ? (row.preBill.oldCusOrderNo ? row.preBill.oldCusOrderNo : row.preBill.sourceOrdNo) : "";
			           }
		            },
	             	{"aTargets": [10],
		              "mRender": function (data, display, row) {
							return  row.preBill ? row.preBill.expressNo : "";
			           }
		            },
	             	{"aTargets": [14],
		              "mRender": function (data, display, row) {
							return new Date(row.createTime.time).Format("yyyy-MM-dd hh:mm:ss");
			           }
		            },
	             	{"aTargets": [15],
		              "mRender": function (data, display, row) {
							return  row.newstatus == "0" ? "新建" :
									row.newstatus == "1" ? "部分收货未上架" :
									row.newstatus == "2" ? "部分收货部分上架" :
									row.newstatus == "3" ? "部分收货完全上架" :
									row.newstatus == "4" ? "完全收货未上架 " :
									row.newstatus == "5" ? "完全收货部分上架" :
									row.newstatus == "6" ? "完全收货完全上架" :
									row.newstatus == "7" ?	"已关闭":
									row.newstatus == "8" ?	"已取消":"";
									
			           }
		            },
	             
	             	{"aTargets": [16],
		              "mRender": function (data, display, row) {
							return  row.creater ? row.creater.realname : "";
			           }
		            },
	             	{"aTargets": [17],
		              "mRender": function (data, display, row) {
		              	var rs = "";
		              	if(row.newstatus=="0"){
		              		if(row.billType == "returnOrder"){
					    		if(row.preBill && row.preBill.returngoodStatus==1){
					    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageCountPageNew/"+row.id+"\"   class=\"btn btn-primary\" >开始收货</a>";
					    		}
					    	}else{
				    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageCountPageNew/"+row.id+"\"   class=\"btn btn-primary\" >开始收货</a>";
					    	}
		              	}else if(row.newstatus=='1'){
			    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageCountPageNew/"+row.id+"\"   class=\"btn btn-primary\" >继续收货</a>";
			    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageUpPageNew/"+row.id+"\"   class=\"btn btn-primary\" >开始上架</a>";
			              	rs += "<a onclick=\"closeBill("+row.id+")\"   class=\"btn btn-primary\" >确认</a>";
		              	}else if(row.newstatus=='2'){
			    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageCountPageNew/"+row.id+"\"   class=\"btn btn-primary\" >继续收货</a>"; 
		              		rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageUpPageNew/"+row.id+"\"   class=\"btn btn-primary\" > 继续上架</a>";
			              	rs += "<a onclick=\"closeBill("+row.id+")\"   class=\"btn btn-primary\" >确认</a>";
		              	}else if(row.newstatus=='3'){
			    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageCountPageNew/"+row.id+"\"   class=\"btn btn-primary\" >继续收货</a>"; 
			    			rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageUpPageNew/"+row.id+"\"   class=\"btn btn-primary\" > 继续上架</a>";
			              	rs += "<a onclick=\"closeBill("+row.id+")\"   class=\"btn btn-primary\" >确认</a>";
		              	}else if(row.newstatus=='4'){
		              		rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageUpPageNew/"+row.id+"\"   class=\"btn btn-primary\" >开始上架</a>";
			              	rs += "<a onclick=\"closeBill("+row.id+")\"   class=\"btn btn-primary\" >确认</a>";
		              	}else if(row.newstatus=='5'){
		              		rs += "<a href=\"${ctx}/v2_instorageBillNew/toInstorageUpPageNew/"+row.id+"\"   class=\"btn btn-primary\" >继续上架</a>";
			              	rs += "<a onclick=\"closeBill("+row.id+")\"   class=\"btn btn-primary\" >确认</a>";
		              	}else if(row.newstatus=='6'){
			              	rs += "<a onclick=\"closeBill("+row.id+")\"   class=\"btn btn-primary\" >确认</a>";
		              	}else if(row.newstatus=='7'){
						    rs += "<button type=\"button\" class=\"btn btn-default\">已确认</button>";
		              	}else if(row.newstatus=='8'){
						    rs += "<button type=\"button\" class=\"btn btn-default\">已取消</button>";
		              	}
						//if(row.status=='5'&&row.customer.openQm=="1"){
						//	rs += "<button type=\"button\"class=\"btn btn-primary\" onclick=\"sendqm('"+row.id+"')\" id=\"sendqm_btn_"+row.id+"\">重发奇门接口</button>";
						//}
						return  rs;
			           }
		            },
	             ]
			});
		}
		//
		function closeBill(id){
			  var result = confirm('您是否确认关闭订单！');
			  if(result){
				  $.ajax({
						type : 'post',
						url : '${ctx}/v2_instorageBillNew/close',
						data : 'billId='+id,
						dataType : 'json',
						success : function(data) {
							if(data.status=="0"){
								alert(data.msg);
								window.location.href="${ctx}/v2_instorageBillNew/v2_toInstorageBillListPage";
							}else{
								alert(data.msg);
							}
						},
						error : function() {
							alert("服务器异常，请重试");
						}
					}); 
			  }
		}
		function filter(item){
			filterParam[item.name] = item;
		}
		function callback(sSource, aoData, fnCallback ) {
		   	var formParam = $("#queryForm").serializeArray();
			for(var n in filterParam){
				formParam.push(filterParam[n]);
			}
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "async":false,
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
			$(nRow).css('background','#B0E2FF');
		}
		
		function load(){
			if($("#queryForm").valid()){
				if (datatable_content) {
					datatable_content.fnDestroy();
				}
				initTable();
			}
		}
		
		  
</script>
</head>

<body>
<section class="content">
 <c:if test="${not empty message}">
		<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
	</c:if>
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<form class="form-search" id="queryForm" >
	    <input id="_orderbystatus" name="_orderbystatus"  value="status" type="hidden"/>
		<div class="form-group row">
			<div class="col-sm-3">
			<div class="input-group col-sm-12">
			    <label class="input-group-text">商家:</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="form-control" onchange="ajaxAreaGroup(this,'_warehouseCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
			</div>
			</div>
				
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">入库仓库:</label>
				   <select  name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  class="form-control" >
				     <option value=""></option>  
				     <c:forEach items="${warehouseList}" var="warehouse">
				       <option value="${warehouse.groupCode}" 
				       <c:if test="${warehouseCode eq warehouse.groupCode }">selected=selected</c:if>
				       >${warehouse.groupName}</option>
				     </c:forEach>
				</select>
			</div>
			</div>
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">入库单状态：</label> 
				<select  name="_newstatus"  id="_newstatus" value="${param._newstatus}"  class="form-control">
				<!-- 0：新建 1:部分收货未上架  2:部分收货部分上架 3:部分收货完全上架 4:完全收货未上架 5:完全收货部分上架 6:完全收货完全上架 7:已关闭 8:已取消 -->
					<option value="" <c:if test="${newstatus eq ''}">selected=selected</c:if> ></option>
				    <option value="0" <c:if test="${newstatus eq '0'}">selected=selected</c:if> >创建</option>
				    <option value="1" <c:if test="${newstatus eq '1'}">selected=selected</c:if> >部分收货未上架</option>
				    <option value="2" <c:if test="${newstatus eq '2'}">selected=selected</c:if> >部分收货部分上架 </option>
				    <option value="3" <c:if test="${newstatus eq '3'}">selected=selected</c:if> >部分收货完全上架</option>
				    <option value="4" <c:if test="${newstatus eq '4'}">selected=selected</c:if> >完全收货未上架</option>
				    <option value="5" <c:if test="${newstatus eq '5'}">selected=selected</c:if> >完全收货部分上架</option>
				    <option value="6" <c:if test="${newstatus eq '6'}">selected=selected</c:if> >完全收货完全上架</option>
				    <option value="7" <c:if test="${newstatus eq '5'}">selected=selected</c:if> >已关闭</option>
				    <option value="8" <c:if test="${newstatus eq '6'}">selected=selected</c:if> >已取消</option>
				</select>
			</div>
			</div>
			
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">入库单号：</label> 
				<input type="text" name="_billCode" id="_billCode"  class="form-control" value="${param._billCode}"/>
		    </div>
		    </div>
		</div>
		<div class="form-group row">
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">入库日期：</label>
				<div class="input-group-addon">
					<i class="fa fa-calendar"></i>
				</div>
			 	<input type="text" name="_fromDate" id="_fromDate"  class="form-control value="${param._fromDate}"/> 
			 </div>
			 </div>
			 
			 <div class="col-sm-3">
			<div class="input-group col-sm-12">	
			 	<label class="input-group-text">至</label>
			 	<div class="input-group-addon">
					<i class="fa fa-calendar"></i>
				</div>
			 	<input type="text" name="_toDate" id="_toDate" class="form-control" value="${param._toDate}" /> 
			 </div>
			 </div>
			 
			 <div class="col-sm-3">
				<div class="input-group col-sm-12">	
				 	<label class="input-group-text">客户单号：</label> 
					<input type="text" name="_customerOrderNo" id="_customerOrderNo"  class="form-control" value=""/>
				 </div>
			 </div>
			 
			 <div class="col-sm-3">
			<div class="input-group col-sm-12">	
			
			    <button type="button" class="btn btn-info" onclick="load()">搜索</button>
			    
			    </div>
			    </div>
			    </div>
		    
	   </form>
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th>序号</th>
		    <th style="width: 60px;">商家</th>
		    <th style="width: 60px;">入库类型</th>
		    <th style="width: 60px;">商品类型</th>
		    <th style="width: 60px;">入库仓</th>
		    <th style="width: 60px;">出库仓</th>
		    <th style="width: 60px;">入库单号</th>
		    <th style="width: 60px;">客户单号</th>
		    <th style="width: 60px;">相关单号</th>
		    <th style="width: 60px;">原始单号</th>
		    <th style="width: 60px;">快递单号</th>
			<th style="width: 60px;">箱子数</th>
			<th style="width: 60px;">SKU数</th>
			<th style="width: 60px;">商品数</th>
			<th style="width: 130px;">登记时间</th>
			<th style="width: 100px;">状态</th>
			<th style="width: 60px;">创建人</th>
			<th style="width: 180px;">管理</th>
		</tr></thead>
		<tbody id="contentTableBody">
		</tbody>
	</table>
	</div>
	</div></div>
	</div>
	
	<!-- 添加/修改入库单 -------------------------------------------------------------------------------------------------->
	<div class="modal fade"  id="detail" >
	<form id="inputForm"  method="post" class="form-horizontal">
		<div class="modal-dialog" style="height: 300px; width: 900px">
			<div class="modal-content"  >
	
		<!-- 头 -->
		<div class="modal-header">
		<span style="font-size: large; font-weight: bold;" id="windowTitle"></span>
		</div>
		<!-- 体 -->
		<div class="modal-body">
						<fieldset>
						      <input type="hidden" id="id" name="id"/>
						      
							  <!-- 行1 -->
						      <div class="form-group row">
								<div class="col-sm-4">
									<div class="input-group col-sm-12">
												<label  class="input-group-text">商家名称:</label>
													 <select  name="customerCode"  id="customerCode"  class="form-control required" onchange="ajaxAreaGroup(this,'inwarehouseCode');">
														<option value=""></option>
														<c:forEach items="${customerList}" var="customer">
														<option value="${customer.customerCode}"  openqm="${customer.openQm}"
														<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>
														>${customer.customerName}</option>
														</c:forEach>
													</select>
							          </div>
							          </div>
							          
				       				<div class="col-sm-4">
									<div class="input-group col-sm-12">
							        
											
												<label  class="input-group-text">入库仓库:</label>
													<select id="inwarehouseCode" name="inwarehouseCode" class="form-control required"   >
														<option value=""></option>
														<c:forEach items="${warehouseList}" var="wm">
															<option value="${wm.groupCode}">${wm.groupName}</option>
														</c:forEach>
													</select>
							          </div>
							          </div>
							          
									<div class="col-sm-4">
									<div class="input-group col-sm-12">						               
							               <label  class="input-group-text" >是否破损:</label>
														<select id="errorFlag" name="errorFlag" class="form-control required" >
															<option value="noterror">完好件</option>
															<option value="error">破损件</option>
														</select>
								         </div>
							          </div>
						       </div>
						       
							       
							   <!-- 行2 -->
							   <div class="form-group row">
								   <div class="col-sm-4">
									<div class="input-group col-sm-12">
											<label  class="input-group-text" >入库类型:</label>
												<select id="billType" name="billType" class="form-control required" onchange="billTypeChange();"  >
													<option value=""></option>
													<option value="customer" selected="selected">采购入库</option>
<!-- 															<option value="allot">调拨入库</option> -->
<!-- 															<option value="cancelOrder">取消单入库</option> -->
<!-- 															<option value="returnOrder">退回件入库</option> -->
												</select>
										   </div>
							          </div>
							          
								    <div class="col-sm-4">
									<div class="input-group col-sm-12">
											<label  class="input-group-text" >相关单号:</label>
											    <input type="text" id="aboutCode" class="form-control" name="aboutCode" placeholder='请录入相关单号...'/>
									</div>
							        </div>
						       </div>           
							       
						      <!-- 行4 -->
						      <div class="form-group row">
						      	<div class="col-sm-12">
								<div class="input-group col-sm-12">
										<label  class="input-group-text" >备注信息:</label>
											<textarea rows="4" id="remarks" class="form-control" name="remarks"  maxlength="100"></textarea>
						    	 </div> 
						    	 </div>
						     </div>
						     
							</fieldset>	      
		      
		</div>
		<!-- 尾 -->
		<div class="modal-footer bg-gray">
			<input id="submit_btn" class="btn btn-primary"  type="button" value="提交" onclick="mySubmit();"/>&nbsp;	
			<input id="cancel_btn" class="btn btn-primary" type="button" data-dismiss="modal" value="返回" />
			<input type="reset" style="display:none;" /> 
		</div>
		</div>
		</div>
        </form> 
     </div>
     <!------------------------------------------------------------------------------------------------------------->
     
     
     <div class="modal fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" style="width:1400;" id="assignSubWarehouseDiv">
			<div class="modal-dialog" >
			<div class="modal-content" >
			<div class="modal-header">
				<h3 id="myModalLabel">
					分配仓库
				</h3>
			</div>
			<div class="modal-body" style="width: 1300;height:300px; overflow: auto;">
				<table class="table table-striped table-bordered table-condensed"
					id="subWarehouseList">
					<thead>
						<tr>
							<th></th>
							<th>仓库编码</th>
							<th>仓库名称</th>
						</tr>
					</thead>
					<tbody id="selectAssignWarehouseBody">
						
					</tbody>
				</table>
			</div>
			<div class="modal-footer">
				<a href="#" onclick="confirmIn()" role="button"  class="btn btn-primary" data-toggle="modal">
					确认登记
				</a>
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>
		</div>
	</div>
	
	<div  class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="countDetail" >
	   <div class="modal-dialog" style="width:1000">
	   <div class="modal-content">
		 <div class="modal-header">
			  <h3 >点收明细</h3>
		  </div>
		  <div class="modal-body" style="width: 1300;height:300px; overflow: auto;">
			  <table id="rdcontentTable" class="table table-striped table-bordered table-condensed" border='1'>
				<thead>
					<tr>
					    <th>序号</th>
					    <th>id</th>
					    <td>LPN</td>
					    <th>收货数量</th>
					    <th>操作</th>
					 </tr>
				 </thead>
				<tbody id="countDetailItem">
				
				</tbody>
			 </table>
		  </div>
		  </div>
		 </div>
	</div>
	
</section>	
</body>
</html>
